package com.system.weirdor.facade.provider.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.system.weirdor.facade.module.param.UserParam;
import com.system.weirdor.facade.provider.UserFacadeApi;
import com.system.weirdor.module.entity.User;
import com.system.weirdor.module.mapper.UserMapper;
import com.system.weirdor.module.service.IRoleService;
import com.system.weirdor.module.service.IUserRoleService;
import com.system.weirdor.module.service.IUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by weirdor on 2017/8/24.
 */
@Service
public class UserFacadeApiImpl implements UserFacadeApi {

    @Autowired
    private IUserService userService;

    @Autowired
    private IUserRoleService userRoleService;

    @Autowired
    private IRoleService roleService;

    @Autowired
    private  UserMapper userMapper;

    public User selectByUserName(String username) {
        if(StringUtils.isBlank(username)){
            return null;
        }
        EntityWrapper<User> wrapper = new EntityWrapper<>();
        wrapper.eq("login_name", username);
        return userService.selectOne(wrapper);
    }
    /**
     * 根据用户Id查询用户信息
     * @param userId 用户Id
     * @return
     */
    @Override
    public User selectUserById(Integer userId) {
    return  userService.selectById(userId);

    }

    /**
     * 用户信息分页显示
     * @param condition 用户实体
     * @Param page
     *
     * @return
     */
    public Page<User> page(User condition, int page, int size) {
        return userService.selectPage(new Page<User>(page, size), new EntityWrapper<User>(condition));
    }




}
